package com.jsh.erp.config;

import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        // 回退到 AntPathMatcher，兼容旧版本宽松路径规则
        configurer.setPathMatcher(new org.springframework.util.AntPathMatcher());
    }

    // 2. 配置 Tomcat 允许特殊字符（解决逗号、[ ] 等问题）
    @Bean
    public ConfigurableServletWebServerFactory webServerFactory() {
        TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
        factory.addConnectorCustomizers(connector -> {
            // 允许 URL 中包含逗号、[、] 等字符
            connector.setAttribute("relaxedQueryChars", ",,[,]");
            connector.setAttribute("relaxedPathChars", ",,[,]");
        });
        return factory;
    }
}
